package com.xiaobai.shardingsphere.mapper;

import com.xiaobai.shardingsphere.entity.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface OrderMapper {
    @Insert("insert into pay_order(user_id,product_name,count) values(#{userId},#{productName},#{count})")
    Long insert(OrderVO orderVO);

    /**
     * 查询订单
     */
    @Select({"<script>" +
            "select * from pay_order p where p.order_id in " +
            "<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>" +
            "limit 1" +
            "</script>"})
    List<Map<String, Object>> findOrderByIds(@Param("orderIds") List<Long> orderIds);

    /**
     * 查询订单
     */
    @Select("select * from pay_order order by user_id asc")
    List<Map<String, Object>> list();
}

